<%--
  Created by IntelliJ IDEA.
  User: xiaodoudou
  Date: 2020/10/29
  Time: 15:22
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

<%String path = request.getContextPath();%>
<html>
<head>

    <meta charset="utf-8">
    <title>登录界面</title>
    <link rel="stylesheet" href="<%=path%>/static/web/css/reset.css" />
    <link rel="stylesheet" href="<%=path%>/static/web/css/common.css" />
    <link rel="stylesheet" href="<%=path%>/static/web/css/font-awesome.min.css" />
    <script type="text/javascript" src="<%=path%>/static/web/js/jquery-3.5.1.min.js"></script>
    <!--滑块-->
    <link rel="stylesheet" type="text/css" href="<%=path%>/static/web/css/verify.slider.css" />
    <script type="text/javascript"  charset="UTF-8" src="<%=path%>/static/web/js/verify.slider.js" ></script>
    <!--好看的弹窗-->
    <link rel="stylesheet" type="text/css" href="https://www.huangwx.cn/css/sweetalert.css">
    <script type="text/javascript" src="https://www.huangwx.cn/js/sweetalert-dev.js"></script>
</head>
<body>
<div class="wrap login_wrap">
    <div class="content">
        <div class="logo"></div>
        <div class="login_box">

            <div class="login_form">
                <div class="login_title">
                    <span><a id="passLogin" style="color: darkorange" href="javascript:void(0)" >密码登录</a> </span>
                    ||
                    <span><a style="color: grey" href="javascript:void(0)" id="mesLogin">短信登录</a></span>
                </div>

                <div id="changeForm">
                <form action="/user/login" method="post" id="myform">

                    <div class="form_text_ipt">
                        <input id="username" name="name" type="text" placeholder="用户名">
                        <span></span>
                    </div>

                    <div class="form_text_ipt">
                        <input id="password" name="password" type="password" placeholder="密码">
                        <span></span>
                    </div>

                        <div  style="margin-left:25px;margin-top: 20px" id="verify_type1"></div>

                    <div class="form_check_ipt">
                        <div class="left check_left">
                            <label><input name="remberMe" id="remberMe" type="checkbox">下次自动登录</label>
                        </div>
                        <div class="right check_right">
                            <a href="#">忘记密码</a>
                        </div>
                    </div>
                    <div class="form_btn">
                        <button type="button" id="login">登录</button>
                    </div>
                    <div class="form_reg_btn">
                        <span>还没有帐号？</span><a href="<%=path%>/user/registe">马上注册</a>
                    </div>
                </form>
                </div>
                <div class="other_login">
                    <div class="left other_left">
                        <span>其它登录方式</span>
                    </div>
                    <div class="right other_right">
                        <a href="#"><i class="fa fa-qq fa-2x"></i></a>
                        <a href="#"><i class="fa fa-weixin fa-2x"></i></a>
                        <a href="#"><i class="fa fa-weibo fa-2x"></i></a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<%--<script type="text/javascript" src="<%=path%>//static/web/js/jquery.min.js" ></script>--%>
<%--<script type="text/javascript" src="<%=path%>//static/web/js/common.js" ></script>--%>

</body>

<!--滑块验证-->
<script type="text/javascript">

    var flag = false;
    $(function () {

        sliding();
    })

    function sliding()
    {
        var type1 = document.getElementById('verify_type1');
        verifyFun.bar({
            dom:type1,		// dom对象
            width:'300',	// 盒子宽
            height:'40',	// 盒子高
            hsize:'15',		// 提示字体大小
            size:'20',		// 滑动块箭头字体大小
            diff:5,			// 误差值
            success:function() {
                flag = true;
            },
            error:function() {
                flag = false;
            }
        });
        return flag;
    }
</script>




<script>
    $(function () {
        //失去焦点验证
        $("#username").blur(checkUsername);
        $("#username").focus(function () {
            $("#username").next().html("");
        })
        //失去焦点验证密码
        $("#password").blur(checkPassword);
        $("#password").focus(function () {
            $("#password").next().html("");
        })

        //表单提交
        $("#login").click(submit);



        <%--ajax换界面内容--%>
        $("#mesLogin").click(function () {
            $.ajax({
                url:"<%=path%>/user/AjaxMesLogin",
                async:false,
                type:"post",
                success:function (mes) {
                    $("#changeForm").html(mes);
                    $("#mesLogin").css("color","darkorange");
                    $("#passLogin").css("color","grey");
                },
            })
        });

        //ajax更换页面内容
        $("#passLogin").click(function () {
            $.ajax({
                url:"<%=path%>/user/AjaxPassLogin",
                async:false,
                type:"post",
                success:function (mes) {
                    $("#changeForm").html(mes);
                    $("#mesLogin").css("color","grey");
                    $("#passLogin").css("color","darkorange");
                },
            })
        });


        //验证用户名
        function checkUsername() {
            var username = $("#username").val();
            var flag = false;
            if(username=="") {
                $("#username").next().html("用户名不能为空呦~");
                $("#username").next().css("color","red");
                return flag=false;
            }
            return flag = true;
        }

        //验证密码
        function checkPassword() {
            var password = $("#password").val();
            var flag = false;
            if(password==""){
                $("#password").next().html("密码不能为空呦~");
                $("#password").next().css("color","red");
                return flag=false;
            }
            return flag = true;
        }

        //表单验证
        function submit() {
            var flag1 = checkUsername();
            var flag2 = checkPassword();
            var flag3 = sliding();
            var username = $("#username").val();
            var password = $("#password").val();
            if(flag1&&flag2&&flag3){
                //验证用户名密码是否正确
                $.ajax({
                    url:"<%=path%>/isRegiste",
                    async:false,
                    data:{"name":username,"password":password},
                    type:"post",
                    success:function (mes) {
                        //用户名密码不对或者没有注册
                        if(mes=="true"){
                            swal("用户名或者密码不对呦~");
                            return false;
                        }
                        if(mes=="false"){
                            $("#myform").submit();

                        }
                    }
                })//ajax结束
            }
        }


    })//网页加载函数结束
</script>
</html>
